<?php
require_once('conn.inc.php');
@$phone 	=	$_POST["phone"];
@$password	=	md5(md5($_POST["password"]));
// @$phone 	=	 	15600993205;
// @$password	=		c3284d0f94606de1fd2af172aba15bf3;
@$logintime	=		time();								//登录时间
@$conn		=		mysql_connect($db_host,$db_user,$db_pwd);

mysql_query("set names 'utf8'");
mysql_select_db($db_name);

if ($phone == null || $password == null) {
	$rc = array('code'=>-1);									           //用户名密码不能为空
	echo json_encode($rc);
}else{
	$find = "select * from member where phone='$phone' && password='$password' ";
	$result = mysql_query($find);
	$num_rows = mysql_num_rows($result);
	if ($num_rows == 1) {
		$dlqx = "select * from member where phone='$phone' && password='$password' && dlqx='1' ";
		$rd = mysql_query($dlqx);
		$nr = mysql_num_rows($rd);
		if ($nr == 1) {
			$login = "UPDATE member SET logintime = '$logintime' WHERE phone = '$phone' && password = '$password' ";
			$results = mysql_query($login);			//记录登录时间
			$row = mysql_fetch_row($rd);
			if($row != null){
				$json = array(							//返回用户信息
						'code'		=>0,
						'id'		=>$row[0],
						'phone'		=>$row[1],
						'password'	=>$row[2],
						'nickname'	=>$row[5],
						'tx'		=>$row[6],
						'sex'		=>$row[7]
				);
			}else{
				$json = array(
						'code'		=>250,
						'rand_num'	=>date('Y/m/d H:i:s')
				);
			}
			echo json_encode($json);
		}else{
			$rc = array('code'=>-3);								//用户禁止登陆，请联系管理员。
			echo json_encode($rc);
		}
	}else{
		$rc = array('code'=>-2);								//用户名或密码错误
		echo json_encode($rc);
	}
}
mysql_close();
